home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SGI Hot Mix 17
/
Hot Mix 17.iso
/
HM17_SGI
/
research
/
examples
/
demo
/
demosrc
/
d_flyby.pro
< prev
next >
Wrap
Text File
|
1997-07-08
|
21KB
|
659 lines
;$Id: d_flyby.pro,v 1.29 1997/04/17 18:35:42 tremblay Exp $
;
; Copyright (c) 1997, Research Systems, Inc. All rights reserved.
; Unauthorized reproduction prohibited.
;
;+
; FILE:
; d_flyby.pro
;
; CALLING SEQUENCE: d_flyby
;
; PURPOSE:
; Shows the texture mapping and a flyby animation.
;
; MAJOR TOPICS: Visualization
;
; CATEGORY:
; IDL 5.0
;
; INTERNAL FUNCTIONS and PROCEDURES:
; pro StopAndReset - Stop the ride sequence and reset
; pro d_flyby_Event - Event handler
; pro d_flyby_Cleanup - Cleanup
; pro d_flyby - Main procedure
;
; EXTERNAL FUNCTIONS, PROCEDURES, and FILES:
; pro trackball__define - Create the trackball object
; pro gettips - Read the tip file
; pro widtips - Create the tip widgets
; pro sizetips - Size the tip widgets
; flyby.txt
; flyby.tip
; leadvil.sav
; elev_t.dat
;
; REFERENCE: IDL Reference Guide, IDL User's Guide
;
; NAMED STRUCTURES:
; none.
;
; COMMON BLOCS:
; none.
;
; MODIFICATION HISTORY:
; 1/97, DAT - Written.
;-
;----------------------------------------------------------------------------
;
; Purpose: Stop the flyby sequence and reset the surface
; to its initial state (Position and orientation).
;
pro StopAndReset, $
sEvent ; IN: event sturcture
WIDGET_CONTROL, sEvent.top, GET_UVALUE=sState, /NO_COPY
sState.oSurfaceModel->SetProperty, $
TRANSFORM=sState.initTranslationTM
sState.oSurfaceRotationModel->SetProperty, $
TRANSFORM=sState.initRotationTM
sState.oWindow->Draw, sState.oView
sState.stopFlag = 0
WIDGET_CONTROL, sState.wRideButton, SENSITIVE=1
WIDGET_CONTROL, sState.wFileButton, SENSITIVE=1
WIDGET_CONTROL, sState.wHelpButton, SENSITIVE=1
WIDGET_CONTROL, sState.wFrameSpeedSlider, SENSITIVE=1
WIDGET_CONTROL, sState.wResetButton, SENSITIVE=0
WIDGET_CONTROL, sEvent.top, /CLEAR_EVENTS
WIDGET_CONTROL, sEvent.top, SET_UVALUE=sState, /NO_COPY
end
;----------------------------------------------------------------------------
;
; Purpose: Event handler.
;
pro d_flyby_event, $
sEvent
if (TAG_NAMES(sEvent, /STRUCTURE_NAME) EQ $
'WIDGET_KILL_REQUEST') then begin
WIDGET_CONTROL, sEvent.top, /DESTROY
RETURN
endif
WIDGET_CONTROL, sEvent.id, GET_UVALUE= uvalue
case uvalue of
'RESET' : begin
WIDGET_CONTROL, sEvent.top, GET_UVALUE=sState, /NO_COPY
; Setting the stopFlag to 1 will stop the for loops
; in 'RIDE' section below.
;
sState.stopFlag = 1
WIDGET_CONTROL, sEvent.top, SET_UVALUE=sState, /NO_COPY
end
; Start the animation.
;
'RIDE' : begin
WIDGET_CONTROL, sEvent.top, GET_UVALUE=sState, /NO_COPY
sState.stopFlag = 0
stopFlag = 0
WIDGET_CONTROL, sState.wRideButton, SENSITIVE=0
WIDGET_CONTROL, sState.wHelpButton, SENSITIVE=0
WIDGET_CONTROL, sState.wFrameSpeedSlider, SENSITIVE=0
WIDGET_CONTROL, sState.wResetButton, SENSITIVE=1
WIDGET_CONTROL, sEvent.top, SET_UVALUE=sState, /NO_COPY
for i = 1, 11 do begin
WIDGET_CONTROL, sEvent.top, GET_UVALUE=sState, /NO_COPY
sState.oSurfaceModel->Translate,0.035, 0.0, 0.13
sState.oSurfaceRotationModel->GetProperty, $
TRANSFORM = tm
sState.oSurfaceRotationModel->Rotate, $
[tm[0,0], tm[0,1], tm[0,2]], -3.5
sState.oWindow->Draw, sState.oView
wait, sState.timeDelay
WIDGET_CONTROL, sEvent.top, SET_UVALUE=sState, /NO_COPY
; Catch the quit ofr close event from the close box.
;
result = WIDGET_EVENT(sEvent.top, /NOWAIT, BAD_ID=badID)
; This event is created by the close box.
; The top level base is destroyed. Upon RETURN,
; the code goes to the cleanup procedure directly.
;
if(badID NE 0) then begin
RETURN
endif
; The stopFlag is set to 1 only by pushing the
; 'Stop and Reset' button. That is event is
; processed after the draw command in the for loops
; below.
;
WIDGET_CONTROL, sEvent.top, GET_UVALUE=sState, /NO_COPY
stopFlag = sState.stopFlag
WIDGET_CONTROL, sEvent.top, SET_UVALUE=sState, /NO_COPY
if (stopFlag EQ 1) then begin
StopAndReset, sEvent
RETURN
endif
endfor
for i = 1, 6 do begin
WIDGET_CONTROL, sEvent.top, GET_UVALUE=sState, /NO_COPY
sState.oSurfaceModel->Translate, -0.012, 0.0, 0.12
sState.oWindow->Draw, sState.oView
wait, sState.timeDelay
WIDGET_CONTROL, sEvent.top, SET_UVALUE=sState, /NO_COPY
; Catch the quit ofr close event from the close box.
;
result = WIDGET_EVENT(sEvent.top, /NOWAIT, BAD_ID=badID)
; This event is created by the close box.
;
if(badID NE 0) then begin
RETURN
endif
; The stopFlag is set to 1 only by pushing the
; 'Stop and Reset' button. That is event is
; processed after the draw command in the for loops
; below.
;
WIDGET_CONTROL, sEvent.top, GET_UVALUE=sState, /NO_COPY
stopFlag = sState.stopFlag
WIDGET_CONTROL, sEvent.top, SET_UVALUE=sState, /NO_COPY
if (stopFlag EQ 1) then begin
StopAndReset, sEvent
RETURN
endif
endfor
for i = 1, 8 do begin
WIDGET_CONTROL, sEvent.top, GET_UVALUE=sState, /NO_COPY
sState.oSurfaceRotationModel->GetProperty, $
TRANSFORM = tm
sState.oSurfaceRotationModel->Rotate, $
[tm[2,0], tm[2,1], tm[2,2]], 15
sState.oWindow->Draw, sState.oView
wait, sState.timeDelay
WIDGET_CONTROL, sEvent.top, SET_UVALUE=sState, /NO_COPY
; Catch the quit ofr close event from the close box.
;
result = WIDGET_EVENT(sEvent.top, /NOWAIT, BAD_ID=badID)
; This event is created by the close box.
;
if(badID NE 0) then begin
RETURN
endif
; The stopFlag is set to 1 only by pushing the
; 'Stop and Reset' button. That is event is
; processed after the draw command in the for loops
; below.
;
WIDGET_CONTROL, sEvent.top, GET_UVALUE=sState, /NO_COPY
stopFlag = sState.stopFlag
WIDGET_CONTROL, sEvent.top, SET_UVALUE=sState, /NO_COPY
if (stopFlag EQ 1) then begin
StopAndReset, sEvent
RETURN
endif
endfor
for i = 1, 5 do begin
WIDGET_CONTROL, sEvent.top, GET_UVALUE=sState, /NO_COPY
sState.oSurfaceModel->translate, 0.0, -0.035, 0.09
sState.oWindow->Draw, sState.oView
wait, sState.timeDelay
WIDGET_CONTROL, sEvent.top, SET_UVALUE=sState, /NO_COPY
; Catch the quit ofr close event from the close box.
;
result = WIDGET_EVENT(sEvent.top, /NOWAIT, BAD_ID=badID)
; This event is created by the close box.
;
if(badID NE 0) then begin
RETURN
endif
; The stopFlag is set to 1 only by pushing the
; 'Stop and Reset' button. That is event is
; processed after the draw command in the for loops
; below.
;
WIDGET_CONTROL, sEvent.top, GET_UVALUE=sState, /NO_COPY
stopFlag = sState.stopFlag
WIDGET_CONTROL, sEvent.top, SET_UVALUE=sState, /NO_COPY
if (stopFlag EQ 1) then begin
StopAndReset, sEvent
RETURN
endif
endfor
; Reset the view to initial transformation.
;
StopAndReset, sEvent
end ; of RIDE
; Set the time delay between each redraw. This time is added to
; to the drawing time.
;
'SPEED': begin
WIDGET_CONTROL, sEvent.top, GET_UVALUE=sState, /NO_COPY
; Get the slider value.
;
WIDGET_CONTROL, sState.wFrameSpeedSlider, GET_VALUE=sValue
; The slider value range is from 0 to 10. Make
; the maximum delay to be 1.0 seconds.
;
sState.timeDelay = 1.0 - (FLOAT(sValue)/ 10.0)
WIDGET_CONTROL, sEvent.top, SET_UVALUE=sState, /NO_COPY
end ; of SPEED
; Handle the event generated within the drawing area
;
'DRAW': begin
WIDGET_CONTROL, sEvent.top, GET_UVALUE=sState, /NO_COPY
; Expose.
;
if (sEvent.type eq 4) then begin
sState.oWindow->Draw, sState.oView
WIDGET_CONTROL, sEvent.top, SET_UVALUE=sState, /NO_COPY
RETURN
endif
WIDGET_CONTROL, sEvent.top, SET_UVALUE=sState, /NO_COPY
end ; of DRAW
'QUIT' : BEGIN
WIDGET_CONTROL, sEvent.top, /DESTROY
end ; of QUIT
'ABOUT' : BEGIN
; Verify that there is only one instance of Xregistered
;
if (Xregistered('XDisplayFile') NE 0) then RETURN
XDisplayFile, filepath("flyby.txt", $
SUBDIR=['examples','demo','demotext']), $
DONE_BUTTON='Done', $
TITLE="Texture", $
GROUP=sEvent.top, WIDTH=55, HEIGHT=14
end ; of ABOUT
endcase
end
;-----------------------------------------------------------------
;
; PURPOSE : cleanup procedure. restore colortable, destroy objects.
;
pro d_flyby_Cleanup, wTopBase
WIDGET_CONTROL, wTopBase, GET_UVALUE=sState, /NO_COPY
; Destroy the top objects.
;
OBJ_DESTROY, sState.oView
OBJ_DESTROY, sState.oImage
OBJ_DESTROY, sState.oText
OBJ_DESTROY, sState.oFont
; Restore the color table.
;
TVLCT, sState.colorTable
if WIDGET_INFO(sState.groupBase, /VALID_ID) then $
WIDGET_CONTROL, sState.groupBase, /MAP
end ; of d_flyby_Cleanup
;-----------------------------------------------------------------
;
; PURPOSE : show the texture mapping capability
;
PRO d_flyby, $
TEXCOORDS = texcoords, $ ; IN: (opt) texture coordinates
GROUP=group, $ ; IN: (opt) group identifier
APPTLB = appTLB ; OUT: (opt) TLB of this application
; Check the validity of the group identifier.
;
ngroup = N_ELEMENTS(group)
if (ngroup NE 0) then begin
check = WIDGET_INFO(group, /VALID_ID)
if (check NE 1) then begin
print,'Error, the group identifier is not valid'
print, 'Return to the main application'
RETURN
endif
groupBase = group
endif else groupBase = 0L
; Get the screen size.
;
Device, GET_SCREEN_SIZE = screenSize
; Set up dimensions of the drawing (viewing) area.
;
xdim = screenSize[0]*0.6
ydim = xdim*0.8
; Get the current color vectors to restore
; when this application is exited.
;
TVLCT, savedR, savedG, savedB, /GET
; Build color table from color vectors
;
colorTable = [[savedR],[savedG],[savedB]]
; Get the tips.
;
sText = getTips(filepath('flyby.tip', $
SUBDIR=['examples','demo', 'demotext']))
; Create widgets.
;
if (N_ELEMENTS(group) EQ 0) then begin
wTopBase = WIDGET_BASE(/COLUMN, $
TITLE="Flyby", $
XPAD=0, YPAD=0, $
/TLB_KILL_REQUEST_EVENTS, $
TLB_FRAME_ATTR=1, MBAR=barBase)
endif else begin
wTopBase = WIDGET_BASE(/COLUMN, $
TITLE="Flyby", $
XPAD=0, YPAD=0, $
/TLB_KILL_REQUEST_EVENTS, $
GROUP_LEADER=group, $
TLB_FRAME_ATTR=1, MBAR=barBase)
endelse
; Create the menu bar. It contains the file/quit,
; edit/ shade-style, help/about.
;
wFileButton = WIDGET_BUTTON(barBase, VALUE='File', /MENU)
wQuitButton = WIDGET_BUTTON(wFileButton, $
VALUE='Quit', UVALUE='QUIT')
; Create the menu bar item help that contains the about button
;
wHelpButton = WIDGET_BUTTON(barBase, VALUE='About', /HELP, /MENU)
wAboutButton = WIDGET_BUTTON(wHelpButton, $
VALUE='About Flyby', UVALUE='ABOUT')
; Create a sub base of the top base (wTopBase)
;
subBase = WIDGET_BASE(wTopBase, COLUMN=2)
; Create the left Base that contains the functionality buttons
; Notably the object list and the option list
;
wLeftbase = WIDGET_BASE(subBase, /ALIGN_CENTER, /COLUMN)
wRideBase = WIDGET_BASE(wLeftBase, YPAD=15, /COLUMN)
wRideBaseLabel = WIDGET_LABEL(wRideBase, $
VALUE = "Helicopter Ride")
wRideButton = WIDGET_BUTTON(wRideBase, $
VALUE='Ride', UVALUE='RIDE')
wSliderBase = WIDGET_BASE(wLeftBase, $
/COLUMN,/ALIGN_CENTER)
wAnimationLbl = WIDGET_LABEL(wSliderBase, $
VALUE='Animation Speed', $
/ALIGN_CENTER)
wfasttLbl = WIDGET_LABEL(wSliderBase, VALUE='Fast', $
/ALIGN_CENTER)
wFrameSpeedSlider = WIDGET_SLIDER(wSliderBase,$
/ALIGN_CENTER, $
/DRAG, VALUE = 10, UVALUE='SPEED', $
MAXIMUM = 10, MINIMUM = 0,/VERTICAL, /SUPPRESS_VALUE)
wSlowLbl = WIDGET_LABEL(wSliderBase, VALUE='Slow', $
/ALIGN_CENTER)
wResetBase = WIDGET_BASE(wLeftBase, $
/COLUMN)
wResetButton = WIDGET_BUTTON(wResetBase, $
VALUE='Stop and Reset', UVALUE='RESET')
; Create the right Base that has the drawing area
;
wRightBase = WIDGET_BASE(subBase, /COLUMN)
; Draw area.
;
wDraw = WIDGET_DRAW(wRightBase, $
GRAPHICS_LEVEL=2, $
XSIZE=xdim, YSIZE=ydim, /BUTTON_EVENTS, $
UVALUE='DRAW', $
RETAIN=0, /EXPOSE_EVENT)
; Create tips texts.
;
wStatusBase = WIDGET_BASE(wTopBase, MAP=0, /ROW)
nWidgets = 2
wText = LONARR(nWidgets)
widTips, wStatusBase, sText.text, XSIZE=36, $
YSIZE=3, NWIDGETS=nWidgets, wText
; Realize the base widget.
;
WIDGET_CONTROL, wTopBase, /REALIZE
; Returns the top level base in the appTLB keyword
;
appTLB = wTopBase
; Size the tips widgets.
;
sizeTips, wTopBase, wText, wStatusBase
WIDGET_CONTROL, wTopBase, SENSITIVE=0
; Grab the window id of the drawable.
;
WIDGET_CONTROL, wDraw, GET_VALUE=oWindow
; Put centerize the surface.
;
bias = -0.5
myview = [0+bias, 0+bias, 1, 1]
; Create view.
;
oView = OBJ_NEW('idlgrview', $
PROJECTION=2, EYE=3, ZCLIP=[2.9,-10.0], $
VIEWPLANE_RECT=myview, COLOR=[0, 0, 0])
; Make the starting up text location centered.
;
textLocation = [myview[0]+0.5*myview[2], myview[1]+0.5*myview[3]]
; Create and display the PLEASE WAIT text.
;
oFont = OBJ_NEW('IDLgrFont', 'Helvetica', SIZE=10)
oText = OBJ_NEW('IDLgrText', $
'Starting up Please wait...', $
ALIGN=0.5, $
LOCATION=textLocation, $
COLOR=[255,255,0], FONT=oFont)
; Create model.
;
oTopModel = OBJ_NEW('idlgrmodel')
oSurfaceModel = OBJ_NEW('idlgrmodel')
oSurfaceRotationModel = OBJ_NEW('idlgrmodel')
oSurfaceScalingModel = OBJ_NEW('idlgrmodel')
oTopModel->Add, oSurfaceModel
oSurfaceModel->Add, oSurfaceRotationModel
oSurfaceRotationModel->Add, oSurfaceScalingModel
; Place the model in the view.
;
oView->Add, oTopModel
; Add the text.
;
oTopModel->Add, oText
; Draw the starting up screen.
;
oWindow->Draw, oView
RESTORE, filepath('lvdem.sav', SUBDIR=['examples','demo','demodata'])
z = lvdemdata
sz = SIZE(z)
maxx = sz[1] - 1
maxy = sz[2] - 1
maxz = MAX(z, MIN=minz)
; Compute coordinate conversion to normalize.
;
xs = [0+bias, 1.0/maxx]
ys = [0+bias, 1.0/maxy]
minz2 = minz - 1000.0
maxz2 = maxz + 1000.0
zs = [-minz2/(maxz2-minz2)+bias, 1.0/(maxz2-minz2)]
; Create texture map. Read the image first.
;
READ_JPEG, filepath('lvimage.jpg', $
SUBDIR=['examples','demo','demodata']), lvimage, TRUE=3
oImage = OBJ_NEW('IDLgrImage', lvimage, INTERLEAVE=2)
; Create the surface object.
;
oSurface = OBJ_NEW('IDLgrSurface', z, STYLE=2, SHADING=1, $
COLOR=[255,255,255], $
TEXTURE_MAP=oImage, $
XCOORD_CONV=xs, YCOORD_CONV=ys, ZCOORD_CONV=zs)
oSurfaceScalingModel->Add, oSurface
z1 = z
oSurface->SetProperty, DATAZ=z1
; Create a light.
;
oLight1 = OBJ_NEW('IDLgrLight', TYPE=0, INTENSITY=1., COLOR=[255,255,255])
oTopModel->Add, oLight1
oLight2 = OBJ_NEW('IDLgrLight', LOCATION=[-2,2,-2], TYPE=1)
oTopModel->Add, oLight2
; Set the initial view.
;
sc = 3.0
oSurfaceScalingModel->Scale, 1.0, 1.0, sc
oSurfaceRotationModel->Rotate, [1,0,0],-35
; Get the initial transformation.
;
oSurfaceModel->GetProperty, TRANSFORM = initTranslationTM
oSurfaceRotationModel->GetProperty, TRANSFORM = initRotationTM
; Create the state structure.
;
sState = { $
btndown: 0b, $ ; 0 = not pressed, 1= pressed
wDraw: wDraw, $ ; Widget draw ID
timeDelay: 0.0, $ ; Animation frame delay (sec.)
OSurfaceModel: oSurfaceModel, $ ; Models
OSurfaceScalingModel: $
oSurfaceScalingModel, $
OSurfaceRotationModel: $
oSurfaceRotationModel, $
OSurface: oSurface, $ ; Surface object
OView: oView, $ ; View object
WTopBase : wTopbase, $ ; Top level base
WFrameSpeedSlider : $
wFrameSpeedSlider, $ ; Animation speed slider
WFileButton : wFileButton, $ ; Buttons ID
WRideButton : wRideButton, $
WResetButton : wResetButton, $
WHelpButton : wHelpButton, $
WQuitButton : wQuitButton, $
OImage: oImage, $ ; Image object
ColorTable: colorTable, $ ; Color table to restore at exit
Z1: z1, $ ; Surface height data
WText: wText, $ ; Widget text IDs for tips
InitTranslationTM: $
initTranslationTM, $ ; Initial transformation matrix
InitRotationTM: initRotationTM, $ ; Initial rotation of surface
OWindow: oWindow, $ ; Window object
OText: oText, $ ; Starting up text object
OFont: oFont, $ ; Starting up text font object
StopFlag: 0, $
groupBase: groupBase $ ; Base of Group Leader
}
WIDGET_CONTROL, wTopBase, SET_UVALUE=sState, /NO_COPY
WIDGET_CONTROL, wTopBase, SENSITIVE=1
WIDGET_CONTROL, wResetButton, SENSITIVE=0
; Remove the starting up text.
;
oTopModel->Remove, oText
; Draw the screen.
;
oWindow->Draw, oView
XMANAGER, 'd_flyby', wTopBase, $
EVENT_HANDLER='d_flyby_event', $
/NO_BLOCK, $
CLEANUP='d_flyby_Cleanup'
end ; of d_flyby